#!/usr/bin/python

import pygame, sys, os
from pygame.locals import *

#initialise screen
pygame.init()
screen = pygame.display.set_mode([800, 600])

#add background
background = pygame.image.load('space_bg.png').convert()
screen.blit(background, (0,0))
pygame.display.update()

#global vairables
isFired = True

#missile class
class Missile(pygame.sprite.Sprite):
    def __init__(self, hero_x):           #hero_x is the temp. variable name for the ship's current x-coordinate
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.Surface([5,20])
        self.image.fill([255,0,0])
        self.rect = self.image.get_rect()
        self.rect.topleft = (hero_x, 560)  #560 is the x-axis the player sits on
        self.next_update_time = 0
        
    def update(self, current_time):
        if self.next_update_time < current_time:
            self.rect.top -= 1

            self.next_update_time = current_time + 10
        
def main():


    #add missile
    missiles = []
    for hero_x in [(200),
                   (400),
                   (600)]:
        missiles.append(Missile(hero_x))

    missiles = pygame.sprite.RenderUpdates()

    while pygame.event.poll().type != KEYDOWN:

        time = pygame.time.get_ticks() 
        for m in missiles:
            m.update(time)
            screen.blit(m.image, m.rect)
                        
        pygame.display.update()
        missiles.clear(screen, background)
                         

if __name__ == '__main__': main()
